package itstudio.instructor.ui;

import java.util.ArrayList;
import java.util.List;
import itstudio.instructor.adapter.UserListAdapter;
import itstudio.instructor.entity.User;
import itstudio.instructor.widget.PagerSlidingTabStrip;
import itstudio.instructor.xlistview.XListView;
import com.easemob.chatuidemo.R;
import android.app.Activity;
import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.text.TextUtils;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.view.inputmethod.EditorInfo;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.TextView.OnEditorActionListener;


/** 
* @Description: my appt
* @author wang
* @date 2015-1-13 上午1:14:21 
*/
public class UserSearchActivity extends Activity implements OnEditorActionListener {


	private PagerSlidingTabStrip tabs;
	private ViewPager pager;
	private EditText et;
    private XListView xListView;
    private UserListAdapter adapter;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		getWindow().setLayout(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
		setContentView(R.layout.activity_user_serch);
		findViews();
		init();
		setListeners();

	}

	protected void findViews() {
		et = (EditText) findViewById(R.id.search_et);
		xListView = (XListView) findViewById(R.id.xlistView);

	}

	protected void init() {

		adapter = new UserListAdapter(this, null);
		xListView.setAdapter(adapter);
		xListView.setPullRefreshEnable(false);
		xListView.setPullLoadEnable(false);
		
	}
	protected void setListeners() {
		
		findViewById(R.id.cancel).setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				finish();
			}
		});
		et.setOnEditorActionListener(this);
	}

	@Override
	public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
        switch(actionId){  
        case EditorInfo.IME_NULL:  
            System.out.println("null for default_content: " + v.getText() );  
            break;  
        case EditorInfo.IME_ACTION_SEND:  
            System.out.println("action send for email_content: "  + v.getText());  
            break;  
        case EditorInfo.IME_ACTION_DONE:  
            System.out.println("action done for number_content: "  + v.getText());  
            break;  
        }  
        //Toast.makeText(this, v.getText()+"--" + actionId, Toast.LENGTH_LONG).show();  
 /*       adapter.clearAll();
        if(!TextUtils.isEmpty(v.getText())&& v.getText().toString().startsWith("孙")){
        	adapter.clearAll();
        	adapter.appendToList(testData());
        }*/
        adapter.clearAll();
    	adapter.appendToList(testData());
        return true;  
	}
	
	private List<User> testData() {
		List<User> userList = new ArrayList<User>();
		User u1= new User();
		u1.setName("孙俪");
		u1.setIntro("婚姻是爱情的坟墓");
		u1.setHeadUrl("drawable://"+R.drawable.t_user_4);
		u1.setFocus(false);
		userList.add(u1);
		User u2= new User();
		u2.setName("孙楠");
		u2.setIntro("欲把相思说似谁，浅情人不知");
		u2.setHeadUrl("drawable://"+R.drawable.t_user_5);
		u2.setFocus(true);
		userList.add(u2);
		User u3= new User();
		u3.setName("教务处");
		u3.setIntro("愿得一心人，白头不相离");
		u3.setHeadUrl("drawable://"+R.drawable.t_user_6);
		u3.setFocus(true);
		userList.add(u3);
		return userList;
	}

}
